// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var dialog = require("dialog");
	var constant = require("constant");
	var router = require("../hash/pageRouter");
	var databind = require("databind");
	var css_detail = require("./pickupDetail.css");
	var css_consent = require("./pickupConsent.css");
	var html_valuation = require("./html_valuation.html");
	var js_platform_main = require("./platform_main.js");
	var valuationCal = require("valuationCal");
	var tools = require("tools");
	var pickupId;
	var fileUuid;
	var pageIndex = 1,
		pageSize = 5,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var html_oppose_pickup = require("./html_opposePickupApplication.html");
	var init = function(page) {
		pickupId = page.params.pickupId;
		//		pickupId = 51;	
		inquirePickupApplicationDetail();
		tools.inquireCommonSelectorList(9, $(".delayReson"));
		$("#pincupCOnsentPickupId").val(pickupId);
		js_platform_main.init(0);
		initEvent();
		router.init();

	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		
		tools.clearNoNumAll($("#pickupConsent"));
		
		$("#pickupConsent .auditRecord").unbind("click").click(function(){
			window.open("../auditRecord/auditRecord.html?recordType=3&recordId=" + pickupId);
		});
		
		$("#pickupConsent .ceoAudit .button-Yes").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "supplementPickupCeoAuditOpinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "保存成功");
				router.route("main/pickupConsent.html?pickupId="+pickupId);
			});
		});
		
		$("#pickupConsent .businessAudit .button-Yes").unbind("click").click(function(){
			if ($("input[name=allowValuation]").val()*1 < $(".bulkstockValuation").html()*1){
				base.alert(2, "当前允许额度小于融资额度，不允许提交！");
				return;
			}
			
			$("#pickupConsent input[name=interestInfo]").val($("#pickupConsent .pickupConsentSum").html());
			$("#pickupConsent").attr("action", "supplementPickupBussinessAuditOpinion");
			databind.submitDom($("#pickupConsent"), function() {
				base.alert(1, "保存成功");
				router.route("main/pickupConsent.html?pickupId="+pickupId);
			});
		});
		
		$("#pickupConsent .audit1 .button-Yes").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "supplementPickupAudit1Opinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "保存成功");
				router.route("main/pickupConsent.html?pickupId="+pickupId);
			});
		});
		
		$("#pickupConsent .operationAudit .button-Yes").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "supplementPickupOperationAuditOpinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "保存成功");
				router.route("main/pickupConsent.html?pickupId="+pickupId);
			});
		});
		
		$("#pickupConsent .financialAudit .button-Yes").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "supplementPickupFinancialAuditOpinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "保存成功");
				router.route("main/pickupConsent.html?pickupId="+pickupId);
			});
		});
		
		$("#pickupConsent .riskAudit .button-Yes").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "supplementPickupRiskAuditOpinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "保存成功");
				router.route("main/pickupConsent.html?pickupId="+pickupId);
			});
		});
		
		$("#pickupConsent .riskMemberAudit .button-Yes").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "supplementPickupRiskMemberAuditOpinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "保存成功");
				router.route("main/pickupConsent.html?pickupId="+pickupId);
			});
		});
		
		$("#pickupConsent .finalAudit .button-Yes").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "supplementPickupFinalAuditOpinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "保存成功");
				router.route("main/pickupConsent.html?pickupId="+pickupId);
			});
		});
		
		$("#pickupConsent .audit2 .button-Yes").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "supplementPickupAudit2Opinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "保存成功");
				router.route("main/pickupConsent.html?pickupId="+pickupId);
			});
		});
		
		//-------------------------
		$("#pickupConsent .audit1 .button-Submit").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "submitPickupAudit1Opinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "提交成功");
				router.route("main/pickupList.html");
			});
		});
		
		$("#pickupConsent .businessAudit .button-Submit").unbind("click").click(function(){
			if ($("input[name=allowValuation]").val()*1 < $(".bulkstockValuation").html()*1){
				base.alert(2, "当前允许额度小于融资额度，不允许提交！");
				return;
			}
			
			$("#pickupConsent input[name=interestInfo]").val($("#pickupConsent .pickupConsentSum").html());
			$("#pickupConsent").attr("action", "submitPickupBussinessAuditOpinion");
			databind.submitDom($("#pickupConsent"), function() {
				base.alert(1, "提交成功");
				router.route("main/pickupList.html");
			});
		});
		
		$("#pickupConsent .operationAudit .button-Submit").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "submitPickupOperationAuditOpinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "提交成功");
				router.route("main/pickupList.html");
			});
		});
		
		$("#pickupConsent .financialAudit .button-Submit").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "submitPickupFinancialAuditOpinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "提交成功");
				router.route("main/pickupList.html");
			});
		});
		
		$("#pickupConsent .riskAudit .button-Submit").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "submitPickupRiskAuditOpinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "提交成功");
				router.route("main/pickupList.html");
			});
		});
		
		$("#pickupConsent .riskMemberAudit .button-Submit").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "submitPickupRiskMemberAuditOpinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "提交成功");
				router.route("main/pickupList.html");
			});
		});
		
		$("#pickupConsent .ceoAudit .button-Submit").unbind("click").click(function(){
			$("#pickupConsent .supplementOpinion").attr("action", "submitPickupCeoAuditOpinion");
			databind.submitDom($("#pickupConsent .supplementOpinion"), function() {
				base.alert(1, "提交成功");
				router.route("main/pickupList.html");
			});
		});
		
		$("#pickupConsent .finalAudit .button-Submit").unbind("click").click(function(){
			$("#pickupConsent").attr("action", "submitPickupFinalAuditOpinion");
			databind.submitDom($("#pickupConsent"), function() {
				base.alert(1, "提交成功");
				router.route("main/pickupList.html");
			});
		});
		
		$("#pickupConsent .audit2 .button-Submit").unbind("click").click(function(){
			$("#pickupConsent").attr("action", "submitPickupAudit2Opinion");
			databind.submitDom($("#pickupConsent"), function() {
				base.alert(1, "提交成功");
				router.route("main/pickupList.html");
			});
		});

		$("#pickupConsentBtn").unbind("click").click(function() {
			if ($("#adjustAmount1").val() == "") {
				$("#adjustAmount1").val(0);
			}
			
			if ($("input[name=allowValuation]").val()*1 < $(".bulkstockValuation").html()*1){
				base.alert(2, "当前允许额度小于融资额度，不允许提交！");
				return;
			}
			
			var pickupConsentAdjustPrice = $(".pickupConsentAdjustPrice").val();
			if (pickupConsentAdjustPrice != 0 && pickupConsentAdjustPrice != "") {
				var delayReson = $(".delayReson").val();
				if (delayReson == "" || delayReson == undefined) {
					base.alert(2, "调整金融请选择调整原因");
					return;
				}
				if ($(".adjustment").val() == "") {
					base.alert(2, "调整金融请输入调整说明");
					return;
				}
			}
			databind.submitDom($("#pickupConsent"), function() {
				base.alert(1, "同意提货成功！");
				js_platform_main.init();
				router.route("main/pickupDetail.html?pickupId="+pickupId);
			});
		});

		$("#pickupConsent").on("change", ".pickupConsentAdjustPrice", function() {
			var p = 0;
			$.each($("#pickupConsent .pickupConsentAdjustPrice"), function() {
				if ($.trim($(this).val()) == "") {
					p += 0;
				} else {
					p += $.trim($(this).val()) * 1;
				}
			});
			$("#adjustAmount").html(p);
			$("#adjustAmount1").val(p);
//			$("#pickupConsent .shouldReturn").html(tools.formatCurrency(($("#pickupConsent #pickupConsentEstimateAmount").html().replace(/,/g,'') * 1 + $("#pickupConsent #pickupConsentBulkstockInterest").html().replace(/,/g,'') * 1 + $("#pickupConsent #pickupConsentBulkstockExpense").html() * 1 + $("#pickupConsent #adjustAmount").html() * 1).toFixed(2)));
			
//			$(".pickupConsentSumChinese").html("<span style='color:red;'>（" + tools.changeMoneyToChinese($("#pickupConsent .shouldReturn").html()) + "）</span>");
		});
		
		$("#pickupConsent").on("click", ".showProductIntroDiv .deleteProductIntro", function() {
			$(this).parent().remove();
			fileUuid = [];
			for (var j = 0; j < $(".showProductIntroDiv .mas").length; j++) {
				fileUuid.push($($(".showProductIntroDiv .mas")[j]).attr("fileUuid"));
			}
			$("input[name=evluationFile]").val(fileUuid);
		});
		
		tools.fileupload($("#pickupConsent #evluationFile"), null, function(data){
			var str = '<div class="showProductIntroDiv"><a target="_blank" class="mas" fileUuid="' + data.result.data[0].fileUuid + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + data.result.data[0].fileUuid + '" class="showProductIntro">' + data.result.data[0].fileName + '</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="deleteProductIntro">x</a></div>'
			$(".fileLabel").before(str);
			
			fileUuid = [];
			for (var j = 0; j < $(".showProductIntroDiv .mas").length; j++) {
				fileUuid.push($($(".showProductIntroDiv .mas")[j]).attr("fileUuid"));
			}
			$("input[name=evluationFile]").val(fileUuid);
		});
	};
	
	var interestChangeEvent = function(financeId, deliveryDate){
		$("#pickupConsent #pickupConsentEstimateAmount1").unbind("change").change(function(){
			var $this = $(this);
//			var it = tools.inquiryFinanceInterest(financeId, $this.val(), deliveryDate);
//			$("#pickupConsent #pickupConsentBulkstockInterest1").val(it);
//			$("#pickupConsent #pickupConsentBulkstockInterest").html(tools.formatCurrency(it));
//			$("#pickupConsent #pickupConsentBulkstockInterestOrigin").html(tools.formatCurrency(it));
			$("#pickupConsent #pickupConsentEstimateAmount").html($this.val());
			if (!isNaN($("#pickupConsent #pickupConsentEstimateAmount1").val()) && !isNaN($("#pickupConsent #pickupConsentBulkstockInterest1").val()) && !isNaN($("#pickupConsent #pickupConsentOtherAmount1").val())) {
				$("#pickupConsent .shouldReturn").html($("#pickupConsent #pickupConsentEstimateAmount1").val()*1+$("#pickupConsent #pickupConsentBulkstockInterest1").val()*1+$("#pickupConsent #pickupConsentOtherAmount1").val()*1);
			
				$("#pickupConsent .pickupConsentSumChinese").html("<span style='color:red;'>（" + tools.changeMoneyToChinese($("#pickupConsent .shouldReturn").html()) + "）</span>");
			}
		});
		
		$("#pickupConsent #pickupConsentBulkstockInterest1").unbind("change").change(function(){
			var $this = $(this);
			$("#pickupConsent #pickupConsentBulkstockInterest").html($this.val());
			$("#pickupConsent #pickupConsentBulkstockInterestOrigin").html($this.val());
			if (!isNaN($("#pickupConsent #pickupConsentEstimateAmount1").val()) && !isNaN($("#pickupConsent #pickupConsentBulkstockInterest1").val()) && !isNaN($("#pickupConsent #pickupConsentOtherAmount1").val())) {
				$("#pickupConsent .shouldReturn").html($("#pickupConsent #pickupConsentEstimateAmount1").val()*1+$("#pickupConsent #pickupConsentBulkstockInterest1").val()*1+$("#pickupConsent #pickupConsentOtherAmount1").val()*1);
			
				$("#pickupConsent .pickupConsentSumChinese").html("<span style='color:red;'>（" + tools.changeMoneyToChinese($("#pickupConsent .shouldReturn").html()) + "）</span>");
			}
		});
		
		$("#pickupConsent #pickupConsentOtherAmount1").unbind("change").change(function(){
			var $this = $(this);
			$("#pickupConsent #pickupConsentBulkstockExpense").html($this.val());
			if (!isNaN($("#pickupConsent #pickupConsentEstimateAmount1").val()) && !isNaN($("#pickupConsent #pickupConsentBulkstockInterest1").val()) && !isNaN($("#pickupConsent #pickupConsentOtherAmount1").val())) {
				$("#pickupConsent .shouldReturn").html($("#pickupConsent #pickupConsentEstimateAmount1").val()*1+$("#pickupConsent #pickupConsentBulkstockInterest1").val()*1+$("#pickupConsent #pickupConsentOtherAmount1").val()*1);
			
				$("#pickupConsent .pickupConsentSumChinese").html("<span style='color:red;'>（" + tools.changeMoneyToChinese($("#pickupConsent .shouldReturn").html()) + "）</span>");
			}
		});
	}
	
	var initInterest = function(){
		
//		var $this = $("#pickupConsent #pickupConsentEstimateAmount1");
//		var it = tools.inquiryFinanceInterest(financeId, $this.val(), deliveryDate);
//		$("#pickupConsent #pickupConsentBulkstockInterest1").val(it);
//		$("#pickupConsent #pickupConsentBulkstockInterest").html(tools.formatCurrency(it));
//		$("#pickupConsent #pickupConsentBulkstockInterestOrigin").html(tools.formatCurrency(it));
//		$("#pickupConsent #pickupConsentEstimateAmount").html($this.val());
//		if (!isNaN($("#pickupConsent #pickupConsentEstimateAmount1").val()) && !isNaN($("#pickupConsent #pickupConsentBulkstockInterest1").val()) && !isNaN($("#pickupConsent #pickupConsentOtherAmount1").val())) {
//			$("#pickupConsent .shouldReturn").html($("#pickupConsent #pickupConsentEstimateAmount1").val()*1+$("#pickupConsent #pickupConsentBulkstockInterest1").val()*1+$("#pickupConsent #pickupConsentOtherAmount1").val()*1);
//		
//			$("#pickupConsent .pickupConsentSumChinese").html("<span style='color:red;'>（" + tools.changeMoneyToChinese($("#pickupConsent .shouldReturn").html()) + "）</span>");
//		}
//		
		$("#pickupConsent #pickupConsentEstimateAmount").html($("#pickupConsent #pickupConsentEstimateAmount1").val());
		$("#pickupConsent #pickupConsentBulkstockInterest").html($("#pickupConsent #pickupConsentBulkstockInterest1").val());
		$("#pickupConsent #pickupConsentBulkstockInterestOrigin").html($("#pickupConsent #pickupConsentBulkstockInterest1").val());
		$("#pickupConsent #pickupConsentBulkstockExpense").html($("#pickupConsent #pickupConsentOtherAmount1").val());
		
		if (!isNaN($("#pickupConsent #pickupConsentEstimateAmount1").val()) && !isNaN($("#pickupConsent #pickupConsentBulkstockInterest1").val()) && !isNaN($("#pickupConsent #pickupConsentOtherAmount1").val())) {
			$("#pickupConsent .shouldReturn").html($("#pickupConsent #pickupConsentEstimateAmount1").val()*1+$("#pickupConsent #pickupConsentBulkstockInterest1").val()*1+$("#pickupConsent #pickupConsentOtherAmount1").val()*1);
		
			$("#pickupConsent .pickupConsentSumChinese").html("<span style='color:red;'>（" + tools.changeMoneyToChinese($("#pickupConsent .shouldReturn").html()) + "）</span>");
		}
	}

	//提货申请明细
	var inquirePickupApplicationDetail = function() {
		base.fnAjax({
			action: "inquireNormalPickupApplicationDetail.json",
			oData: {
				pickupId: pickupId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					if (data.datas[0].pickupMethod != 1) {
						$("#pickupConsentEstimateAmount1").parent().addClass("none");
						$("#pickupConsentBulkstockInterest1").parent().addClass("none");
					}
					
					var inventoryIds = [];
					var financeId = data.datas[0].financeId;
					var cutoffDate = data.datas[0].deliveryDate.substring(0, 10);
					var quantitys = [];
					var bulkstockIds = [];
					var aj = 0;
					$.each(data.datas[0].containerInventorys, function() {
						aj += this.adjustment*1;
						if ($.trim(this.inventoryId) != "" && $.trim(this.inventoryId) != null) {
							inventoryIds.push(this.inventoryId);
						}
					});
					
					$.each(data.datas[0].pickupBulkstocks, function() {
						bulkstockIds.push(this.bulkstockId);
						quantitys.push(this.quantity);
					});

					juicer.register("getValueByKey", constant.getValueByKey);
					juicer.register("formatCurrency", tools.formatCurrency);

					var tpl = $("#pickupConsentBulkstockTpl").html();
					var html = juicer(tpl, data);
					$("#pickupConsentBulkstockBody").html(html);
					
//					var tpl2 = $("#exchangeContainerInventoryTpl1").html();
//					var html2 = juicer(tpl2, data);
//					$("#exchangeContainerInventoryBody1").html(html2);
					
					var tpl3 = $("#exchangeBulkstockInfoTpl1").html();
					var html3 = juicer(tpl3, data);
					$("#exchangeBulkstockInfoBody1").html(html3);
					
					$.each($(".evaluatePrice"), function(){
						$(this).parent().find(".valuationChinese").html(tools.changeMoneyToChinese($(this).parent().find(".evaluatePrice").val()));
					});

					//重新估值
					$(".valuation_consent").unbind("click").click(function() {
						var unit = "";
						var quantity = 0;
						if ($(this).attr("measurement") == 1) {
							unit = "体积：";
							quantity = $(this).attr("volume");
						} else if ($(this).attr("measurement") == 2) {
							unit = "重量：";
							quantity = $(this).attr("weight");
						}
						var conversionfactor = $(this).attr("conversionfactor");
						valuationCal.showCal("重新估值", $(this).attr("bulkstockInfoId"), unit, quantity, $(this).parent().find(".pickupConsentValuation"), $(this).parents("tr").find(".bulkstockPrice"), conversionfactor);
					});
					
					$(".valuationLink").unbind("click").click(function(){
						valuationCal.showCal("重新估值", $(this).attr("bulkstockInfoId"), "重量", $(this).attr("weight"), $(this).parent().find(".evaluatePrice"), $(this).parent().find("input[name=evaluatePrice]"), 1);
						$(this).parent().find(".valuationChinese").html(tools.changeMoneyToChinese($(this).parent().find(".evaluatePrice").val()));
					});
					
					databind.fillForm($("#pickupConsent"), data.datas[0]);
					
					$.each($(".auditInfo .data"), function() {
						var $this = $(this);
						if ($.trim($this.html()).length == 0) {
							$this.parents(".auditInfo").remove();
						}
					});
					
					if (data.datas[0].pickupMethod != 1) {
						$("#pickupConsent .riskAudit").remove();
						$("#pickupConsent .riskMemberAudit").remove();
						$("#pickupConsent .audit1").remove();
						$("#pickupConsent .finalAudit").remove();
						$("#pickupConsent .audit2").remove();
					}
					
					if ($("#pickupConsent input[name=ceoAuditSubmitState]").val() == "false") {
						$("#pickupConsent .businessAudit .button-submit").remove();
						$("#pickupConsent .riskAudit .button-submit").remove();
						$("#pickupConsent .riskMemberAudit .button-submit").remove();
						$("#pickupConsent .financialAudit .button-submit").remove();
						$("#pickupConsent .operationAudit .button-submit").remove();
						$("#pickupConsent .audit1 .button-submit").remove();
						$("#pickupConsent .finalAudit .button-submit").remove();
						$("#pickupConsent .audit2 .button-submit").remove();
					}
					
					if ($("#pickupConsent input[name=businessAuditSubmitState]").val() == "false") {
						$("#pickupConsent .riskAudit .button-submit").remove();
						$("#pickupConsent .riskMemberAudit .button-submit").remove();
						$("#pickupConsent .financialAudit .button-submit").remove();
						$("#pickupConsent .operationAudit .button-submit").remove();
						$("#pickupConsent .audit1 .button-submit").remove();
						$("#pickupConsent .finalAudit .button-submit").remove();
						$("#pickupConsent .audit2 .button-submit").remove();
					}
					
					if ($("#pickupConsent input[name=riskAuditSubmitState]").val() == "false") {
						$("#pickupConsent .riskMemberAudit .button-submit").remove();
						$("#pickupConsent .financialAudit .button-submit").remove();
						$("#pickupConsent .operationAudit .button-submit").remove();
						$("#pickupConsent .audit1 .button-submit").remove();
						$("#pickupConsent .finalAudit .button-submit").remove();
						$("#pickupConsent .audit2 .button-submit").remove();
					}
					
					if (data.datas[0].pickupMethod != 1) {
						if ($("#pickupConsent input[name=businessAuditSubmitState]").val() == "false") {
							$("#pickupConsent .financialAudit .button-submit").remove();
							$("#pickupConsent .operationAudit .button-submit").remove();
							$("#pickupConsent .audit1 .button-submit").remove();
							$("#pickupConsent .finalAudit .button-submit").remove();
							$("#pickupConsent .audit2 .button-submit").remove();
						}
					}else {
						if ($("#pickupConsent input[name=riskMemberAuditSubmitState]").val() == "false") {
							$("#pickupConsent .financialAudit .button-submit").remove();
							$("#pickupConsent .operationAudit .button-submit").remove();
							$("#pickupConsent .audit1 .button-submit").remove();
							$("#pickupConsent .finalAudit .button-submit").remove();
							$("#pickupConsent .audit2 .button-submit").remove();
						}
					}
					
					if ($("#pickupConsent input[name=financialAuditSubmitState]").val() == "false") {
						$(".operationAudit .button-submit").remove();
						$(".audit1 .button-submit").remove();
						$(".finalAudit .button-submit").remove();
						$("#pickupConsent .audit2 .button-submit").remove();
					}
					
					if ($("#pickupConsent input[name=operationAuditSubmitState]").val() == "false") {
						$(".audit1 .button-submit").remove();
						$(".finalAudit .button-submit").remove();
						$("#pickupConsent .audit2 .button-submit").remove();
					}
					
					if ($("#pickupConsent  input[name=auditSubmitState1]").val() == "false") {
						$("#pickupConsent .finalAudit .button-submit").remove();
						$("#pickupConsent .audit2 .button-submit").remove();
					}
					
					if ($("#pickupConsent  input[name=finalAuditSubmitState]").val() == "false") {
						$("#pickupConsent .audit2 .button-submit").remove();
					}

					$.each($("#pickupConsent .submitState"), function() {
						var $this = $(this);
						if ($this.val() == "true") {
							$this.parent().find(".auditInfo").after("<span style='color:red; margin-left: 15px;'>已提交</span>");
						} else {
							$this.parent().find(".auditInfo").after("<span style='color:red; margin-left: 15px;'>待提交</span>");
						}
					});
					
//					$(".bulkstockValuation").html($(".bulkstockValuation").html()*1 + aj);
					
					if (data.datas[0].pickupMethod != 1) {
						$(".pickupConsentSum").addClass("none");
					}
					
					if (data.datas[0].pickupMethod != 3) {
						$(".pickupConsentSum1").addClass("none");
					}
					
					$("#pickupConsent .shouldReturn").html(tools.formatCurrency(($("#pickupConsent #pickupConsentEstimateAmount").html().replace(/,/g,'') * 1 + $("#pickupConsent #pickupConsentBulkstockInterest").html().replace(/,/g,'') * 1 + $("#pickupConsent #pickupConsentBulkstockExpense").html() * 1 + $("#pickupConsent #adjustAmount").html() * 1).toFixed(2)));
					$(".pickupConsentSumChinese").html("<span style='color:red;'>（" + tools.changeMoneyToChinese($("#pickupConsent .shouldReturn").html()) + "）</span>");
					
					var fs = $("input[name=evluationFile]").val().split(",");
					for (var j = 0; j < fs.length; j++) {
						if ($.trim(fs[j]) != "") {
							$("#pickupConsent .fileLabel").before('<div class="showProductIntroDiv"><a target="_blank" class="mas" fileUuid="' + fs[j] + '" href="/finance/api/v1.0/downloadFile.file?fileUuid=' + fs[j] + '" class="showProductIntro">'+ tools.inquireFile(fs[j]) +'</a>&nbsp;&nbsp;&nbsp;&nbsp;<a class="deleteProductIntro permissionLink" permissionId="pickupConsentBusinessAudit_1">x</a></div>');
						}
					}
					
					if ($("#pickupConsent input[name=businessAuditSubmitState]").val() == "true") {
						$("#pickupConsent #pickupConsentBulkstockInterest1").attr("disabled", "disabled");
						$("#pickupConsent #pickupConsentEstimateAmount1").attr("disabled", "disabled");
						$("#pickupConsent #pickupConsentOtherAmount1").attr("disabled", "disabled");
						$("#pickupConsent input[name=allowValuation]").attr("disabled", "disabled");
						$("#pickupConsent .pickupConsentAdjustPrice").attr("disabled", "disabled");
						$("#pickupConsent .valuation_consent").addClass("none");
						$("#pickupConsent .pickupConsentValuation").attr("disabled", "disabled");
						$("#pickupConsent .delayReson").attr("disabled", "disabled");
						$("#pickupConsent .adjustment").attr("disabled", "disabled");
						$("#pickupConsent .calcInterest").hide();
					}
					tools.inquireCurrentOperationList($("#pickupConsent"));
					
					initInterest();
					interestChangeEvent(data.datas[0].financeId, data.datas[0].deliveryDate);
					
					//利息计算
					$("#pickupConsent .calcInterest").unbind("click").click(function(){
						var $this = $("#pickupConsent #pickupConsentEstimateAmount1");
						var it = tools.inquiryFinanceInterest(data.datas[0].financeId, $this.val(), data.datas[0].deliveryDate);
						$("#pickupConsent #pickupConsentBulkstockInterest1").val(it);
						$("#pickupConsent #pickupConsentBulkstockInterest").html(tools.formatCurrency(it));
						$("#pickupConsent #pickupConsentBulkstockInterestOrigin").html(tools.formatCurrency(it));
						$("#pickupConsent #pickupConsentEstimateAmount").html($this.val());
						if (!isNaN($("#pickupConsent #pickupConsentEstimateAmount1").val()) && !isNaN($("#pickupConsent #pickupConsentBulkstockInterest1").val()) && !isNaN($("#pickupConsent #pickupConsentOtherAmount1").val())) {
							$("#pickupConsent .shouldReturn").html($("#pickupConsent #pickupConsentEstimateAmount1").val()*1+$("#pickupConsent #pickupConsentBulkstockInterest1").val()*1+$("#pickupConsent #pickupConsentOtherAmount1").val()*1);
						
							$("#pickupConsent .pickupConsentSumChinese").html("<span style='color:red;'>（" + tools.changeMoneyToChinese($("#pickupConsent .shouldReturn").html()) + "）</span>");
						}
					});
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	};

	//最新商品采集价格列表
	var inquireBulkstockLatestCollectionList = function(bulkstockInfoId) {
		base.fnAjax({
			action: "inquireBulkstockLatestCollectionList.json",
			async: false,
			oData: {
				pageSize: pageSize,
				pageIndex: pageIndex,
				bulkstockInfoId: bulkstockInfoId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					var tpl = $("#bulkstockCollectionListTpl").html();
					var html = juicer(tpl, data);
					$("#bulkstockCollectionListBody").html(html);

					totalPageCount = data.totalPageCount;
					totalRecordCount = data.totalRecordCount;
					base.pageControl($("#valuationPagenation"),
						totalRecordCount,
						data.pageIndex,
						data.pageSize,
						function(p) {
							pageIndex = p;
							inquireBulkstockLatestCollectionList();
						});

					$(".priceCheck").on("click", function() {
						$(".valuationRegionPrice").val(($(this).parents("tr").find(".price").html()).toFixed(6));
						var valuationRegionPrice = $(".valuationRegionPrice").val();
						var valuationQuantity = $(".valuationQuantity").val();
						if (valuationRegionPrice == "") {
							valuationRegionPrice = 0;
						}
						if (valuationQuantity == "") {
							valuationQuantity = 0;
						}
						$("#valuationPrice").html((valuationRegionPrice * valuationQuantity).toFixed(2));
					});
				} else {
					//                  base.alert(2,"信息获取失败");
				}
			}
		});
	};

	return {
		init: init
	};
});